<template>
  <!-- 添加或修改请假申请对话框 -->
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="80vw" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="150px">
      <form-block-title title="基础信息"/>
      <el-row>
        <el-col :span="10">
          <el-form-item label="请假类型" prop="type">
            <el-input :value="typeFormat(form)" placeholder="请选择请假类型" readonly/>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="标题" prop="title">
            <el-input v-model="form.title" placeholder="请输入标题" readonly/>
          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item label="原因" prop="reason">
            <el-input v-model="form.reason" type="textarea" placeholder="请输入内容" readonly/>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="开始时间" prop="leaveStartTime">
            <el-date-picker clearable style="width: 100%;"
                            v-model="form.leaveStartTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            readonly
                            placeholder="选择开始时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="结束时间" prop="leaveEndTime">
            <el-date-picker clearable style="width: 100%;"
                            v-model="form.leaveEndTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            readonly
                            placeholder="选择结束时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" readonly/>
          </el-form-item>
        </el-col>
      </el-row>
      <form-block-title title="业务进度"/>
      <el-row>
        <approval-history :business-id="form.id" module-key="leave_application"
                          :instance-id="form.instanceId"
                          ref="approvalHistory" v-if="form.id">
        </approval-history>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { getLeaveApplication, } from '@/api/example/leaveappr/base'
  import FormBlockTitle from '@/components/ScFormBlockTitle/index'
  import ApprovalHistory from '@/components/ApprovalHistory/index'

  export default {
    name: 'Edit',
    components: { FormBlockTitle, ApprovalHistory },
    data() {
      return {
        id: -1,
        // 弹出层标题
        title: '详情信息',
        // 是否显示弹出层
        open: false,
        // 请假类型字典
        typeOptions: [],
        // 表单参数
        form: {}
        ,
        // 表单校验
        rules: {}
      }

    },
    created() {
      this.getDicts('sys_notice_type').then(response => {
        this.typeOptions = response.data
      })
    },
    methods: {
      init(id) {
        //编辑页面加载数据
        if (id && id !== -1) {
          this.id = id
          getLeaveApplication(id).then(response => {
            this.form = response.data
          })
        }
      },
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          type: null,
          title: null,
          reason: null,
          leaveStartTime: null,
          leaveEndTime: null,
          instanceId: null,
          state: null,
          aclDeptId: null,
          aclCreateById: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null
        }

        this.resetForm('form')
      },
      typeFormat(row) {
        return this.selectDictLabel(this.typeOptions, row.type)
      },
      approvalCallback() {
        this.cancel()
      },
    }
  }
</script>
